package com.fa4j.system.file.controller;

import com.fa4j.system.file.SystemFileClient;
import com.fa4j.system.file.model.SysFile;
import com.fa4j.system.file.repository.SysFileRepository;
import com.fa4j.system.file.service.SysFileService;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Hidden
@Tag(name = "系统文件")
@RestController
@RequestMapping("system/file")
@RequiredArgsConstructor
public class SysFileApiController implements SystemFileClient {

    private final SysFileService sysFileService;
    private final SysFileRepository sysFileRepository;

    /**
     * 根据 id 查询文件地址
     *
     * @param fileIds 账号 ID 集合
     * @return 账号列表
     */
    @Override
    public Map<Long, String> queryFileUrlByIds(Collection<Long> fileIds) {
        Map<Long, String> result = new HashMap<>();
        List<SysFile> fileList = sysFileRepository.queryByIds(fileIds);
        fileList.forEach(file -> {
            sysFileService.setFileUrl(file);
            result.put(file.getId(), file.getFileUrl());
        });
        return result;
    }
}
